import Bar from "@/components/j-svg/bar.vue";
import TopLoad from "@/components/j-svg/topload.vue";
import ShiJian from "@/components/j-svg/shijian.vue";
import TWT from "@/components/j-svg/flex_twt.vue";
import TG from "@/components/j-svg/flex_tg.vue";
import { useKline } from "@/stores/kline";
import { top } from "@/comm/tools";
import { shallowRef } from "vue";
import { Core } from "@/comm/Core";
enum Btn {
    TOPLOAD,
    SHIJIAN,
    BAR,
    TWT,
    TG
}

const btnA = [{
    icon: TopLoad,
    val: Btn.TOPLOAD,
    dot: true
},
{
    icon: ShiJian,
    val: Btn.SHIJIAN,
    dot: true
},
{
    icon: Bar,
    val: Btn.BAR,
    dot: true
},
{
    icon: TWT,
    val: Btn.TWT,
    dot: Core.ins.isRedDot("DATE_TW")
},
{
    icon: TG,
    val: Btn.TG,
    dot: Core.ins.isRedDot("DATE_TG")
},
];

const btnB = [{
    icon: TopLoad,
    val: Btn.TOPLOAD,
    dot: false
},
{
    icon: TWT,
    val: Btn.TWT,
    dot: Core.ins.isRedDot("DATE_TW")

},
{
    icon: TG,
    val: Btn.TG,
    dot: Core.ins.isRedDot("DATE_TG")
},
];
const YFloatBtn = {
    btns: shallowRef(btnA),
    onClick: function (e: Btn) {
        // console.log('yzt', e);

        const kline = useKline();
        switch (e) {
            case Btn.SHIJIAN: kline.chilageTableRecommend(!kline.TableRecommend); break;
            case Btn.BAR: kline.changeLinkVisible(!kline.linkVisible); break;
            case Btn.TOPLOAD: top(document.body); break;
            case Btn.TWT:
                this.goPage("https://twitter.com/ChainingView")
                Core.ins.clearRedDot("DATE_TW")
                this.updateBtn(Btn.TWT);
                break;
            case Btn.TG:
                this.goPage("https://t.me/Chainingview")
                Core.ins.clearRedDot("DATE_TG")
                this.updateBtn(Btn.TG);
                break;
        }
    },
    updateBtn(n:any){
        let temp = [...this.btns.value];
        temp.forEach(i => {
            if (i.val == n) {
                i.dot = false
            }
        })
        console.log("temp 变成", temp)
        this.btns.value = temp;
    },
    isHome(path: string) {
        const urls = ['/', /\/coin/g];
        // const urls = ['/home', /\/coin/g];
        const bol = urls.some(url => path.match(url));
        if (bol) {
            this.btns.value = btnA;
        } else {
            this.btns.value = btnB;
        }
    },
    // 点击跳转外部链接
    goPage(url: any) {
        window.open(url)
    }
}

export { YFloatBtn };

